<?php

namespace App\Http\Middleware;

use Closure;
use Route;
use App\Customers;



class HomeValidation
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        //登录状态检测中间件
        if($token = $request->session()->get('remt')){

            $cus = Customers::where('remember_token','=',$token)->first();
            if($cus->remember_token == $token){
                return $next($request);
            }
        }
        $route = Route::current();
        $parm = $route->parameterNames();
        $parms = '';
        if(!empty($parm)){
            foreach($parm as $p){
                $parms = $parms.$route->parameter($p).'/';
            }
        }
        $rout = class_basename(Route::currentRouteAction());
        $request->session()->put('address',$rout);
        $request->session()->put('parm',$parms);
        return redirect('home/login');
    }
}
